package ycobi.cafe24.com;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import android.util.Log;

public class XmlParser {
	
	public ArrayList<Object> Xml(String url_str, String tag_str,int col_count){
    	String rss = url_str;
    	String tag_name = tag_str;
    	int column_count = col_count;
    	
    	ArrayList<Object> temp_arr = new ArrayList<Object>();
    	ArrayList<String> temp_str = new ArrayList<String>();    	
    	try{
    		XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    		factory.setNamespaceAware(true);
    		XmlPullParser xpp = factory.newPullParser();
    		
    		URL url = new URL(rss);
    		InputStream is  = url.openStream();
    		xpp.setInput(is,"EUC-KR");
    		int eventType = xpp.getEventType();
   		
    		
    		while(eventType != XmlPullParser.END_DOCUMENT){
    			if(eventType == XmlPullParser.START_TAG){    				
    				if(xpp.getName().equals(tag_name)){    					   					
    					temp_str.add( xpp.nextText() );
    				}
    			}
    			eventType = xpp.next();
    		}
    		int n = 0;
    		for(int i=0 ; i<temp_str.size() ; i++){    			
    			ArrayList<String> temp_al = new ArrayList<String>();
    			for(int j=0 ; j<column_count ; j++){
    				temp_al.add(temp_str.get(n));
    				n++;
    			}
    			temp_arr.add(temp_al);
    		}		
    	}catch(Exception e){ e.printStackTrace();}    	
    	return temp_arr;
	}
}
